package com.denso.workflow.admin.operator;

import com.denso.workflow.common.model.Operator;

import java.util.List;

public class OperatorService {

    private static final Operator dao = new Operator();

    public List<Operator> find() {
        List<Operator> operatorList = dao.find("select * from operator order by id desc");
        return  operatorList;
    }

    public List<Operator> findByName(String name) {
        List<Operator> operatorList = dao.find("select * from operator where name=?", name);
        return operatorList;
    }

    public Operator findById(int id) {
        return dao.findById(id);
    }

    public boolean save(Operator operator) {
        return operator.save();
    }

    public boolean update(Operator operator) {
        return operator.update();
    }

    public boolean deleteById(int id) {
        return dao.deleteById(id);
    }

    public boolean login(String name, String password) {
        List<Operator> operatorList = dao.find("select * from operator where name=? and password=?", name, password);
        if(operatorList != null && operatorList.size() > 0) {
            return true;
        } else {
            return false;
        }
    }
}
